// 教室控制页js
$(function(){
    // 页面内容自动垂直居中
    // sh.verticalCenter();

    if(sh.isLogin){


    }else{
        // 未登录状态(isLogin=false)按钮禁用

    }

    //页面初始化时，默认显示不限类型的数据
    // classesList是不限类型的模拟数据，后台通过ajax获取，回调sh.createList方法渲染列表
    var classesList = [
        {
            id:0,
            classTitle:"关山高中高二美术集训关山高中高二美术集训",
            addtress:"江汉大学文理学院江汉大学文理学院",
            teacher:"魏坤",
            time:"2018/12/07 18:00",
            classStatus:1, // 1为正在直播，2为即将开始，3为已结束
            imageUrl:"images/bac/class_img.png",
            spaceNum:"3500000",
            isInitedUser:false, //用户是否被邀请
            isInitedSpace:false, //空间是否被邀请
            grade:"高二",
            classCategory:"美术"
        },
        {
            id:1,
            classTitle:"光谷高中高三物理集训",
            addtress:"高三（4）班",
            teacher:"李白",
            time:"2018/11/07 15:00",
            classStatus:2,
            imageUrl:"images/bac/class_img.png",
            spaceNum:"3500001",
            isInitedUser:true, //用户是否被邀请
            isInitedSpace:true, //空间是否被邀请
            grade:"高三",
            classCategory:"物理"
        },
        {
            id:2,
            classTitle:"武汉小学一年级数学集训",
            addtress:"一年级（2）班",
            teacher:"杜甫",
            time:"2018/12/25 17:00",
            classStatus:3,
            imageUrl:"",
            spaceNum:"3500002",
            isInitedUser:true, //用户是否被邀请
            isInitedSpace:true, //空间是否被邀请
            grade:"一年级",
            classCategory:"数学"
        },
        {
            id:3,
            classTitle:"武汉小学三年级语文集训",
            addtress:"三年级（2）班",
            teacher:"辛弃疾",
            time:"2018/10/25 2:30",
            classStatus:1,
            imageUrl:"images/bac/class_img.png",
            spaceNum:"3500003",
            isInitedUser:true, //用户是否被邀请
            isInitedSpace:true, //空间是否被邀请
            grade:"三年级",
            classCategory:"语文"
        },
        {
            id:4,
            classTitle:"武汉小学五年级英语集训",
            addtress:"五年级（2）班",
            teacher:"王之涣",
            time:"2018/10/31 3:30",
            classStatus:2,
            imageUrl:"images/bac/class_img.png",
            spaceNum:"3500004",
            isInitedUser:true, //用户是否被邀请
            isInitedSpace:true, //空间是否被邀请
            grade:"五年级",
            classCategory:"英语"
        },
        {
            id:5,
            classTitle:"关山高中高二美术集训",
            addtress:"高二（4）班",
            teacher:"魏坤",
            time:"2018/12/07 18:00",
            classStatus:3,
            imageUrl:"",
            spaceNum:"3500000",
            isInitedUser:true, //用户是否被邀请
            isInitedSpace:true, //空间是否被邀请
            grade:"高二",
            classCategory:"美术"
        },
        {
            id:6,
            classTitle:"光谷高中高三物理集训",
            addtress:"高三（4）班",
            teacher:"李白",
            time:"2018/11/07 15:00",
            classStatus:1,
            imageUrl:"images/bac/class_img.png",
            spaceNum:"3500001",
            isInitedUser:false, //用户是否被邀请
            isInitedSpace:false, //空间是否被邀请
            grade:"高三",
            classCategory:"物理"
        },
        {
            id:7,
            classTitle:"武汉小学一年级数学集训",
            addtress:"一年级（2）班",
            teacher:"杜甫",
            time:"2018/12/25 17:00",
            classStatus:3,
            imageUrl:"images/bac/class_img.png",
            spaceNum:"3500002",
            isInitedUser:false, //用户是否被邀请
            isInitedSpace:false, //空间是否被邀请
            grade:"一年级",
            classCategory:"数学"
        },
        {
            id:8,
            classTitle:"武汉小学三年级语文集训",
            addtress:"三年级（2）班",
            teacher:"辛弃疾",
            time:"2018/10/25 2:30",
            classStatus:2,
            imageUrl:"",
            spaceNum:"3500003",
            isInitedUser:false, //用户是否被邀请
            isInitedSpace:false, //空间是否被邀请
            grade:"三年级",
            classCategory:"语文"
        },
        {
            id:9,
            classTitle:"武汉小学五年级英语集训",
            addtress:"五年级（2）班",
            teacher:"王之涣",
            time:"2018/10/31 3:30",
            classStatus:2,
            imageUrl:"images/bac/class_img.png",
            spaceNum:"3500004",
            isInitedUser:true, //用户是否被邀请
            isInitedSpace:true, //空间是否被邀请
            grade:"五年级",
            classCategory:"英语"
        },
        {
            id:10,
            classTitle:"武汉小学一年级数学集训",
            addtress:"一年级（2）班",
            teacher:"杜甫",
            time:"2018/12/25 17:00",
            classStatus:3,
            imageUrl:"",
            spaceNum:"3500002",
            isInitedUser:false, //用户是否被邀请
            isInitedSpace:false, //空间是否被邀请
            grade:"一年级",
            classCategory:"数学"
        },
        {
            id:11,
            classTitle:"武汉小学三年级语文集训",
            addtress:"三年级（2）班",
            teacher:"辛弃疾",
            time:"2018/10/25 2:30",
            classStatus:1,
            imageUrl:"images/bac/class_img.png",
            spaceNum:"3500003",
            isInitedUser:false, //用户是否被邀请
            isInitedSpace:false, //空间是否被邀请
            grade:"三年级",
            classCategory:"语文"
        }
    ];
    var defaultImgUrl = "images/bac/default_class_img.png";

    // sh.createList 第一个参数为需渲染的数据，第二个参数为需要渲染的dom外层节点,第三个参数为默认图片的地址
    sh.createList(classesList,8,".classes-list",defaultImgUrl);

    // 点击筛选链接获取对应的数据
    $(".select-list").on("click","dl dd a",function(){

        // category=1 =》获取不限类型，2 =》获取正在直播类型的数据，3=》获取即将直播类型数据，4=》获取直播回放类型数据，5=》获取邀请我的类型数据
        var category = $(this).attr("index");
        $(this).parent("dd").parent("dl").find("a").removeClass("active");
        $(this).addClass("active");
        // 添加一个搜索条件selectOption作为同时需要满足的条件
        var selectOption = "";
        selectOption = $(".searchOption").length > 0 && $.trim($(".searchOption").text());
        // console.log(selectOption);

        // ...请后台将$.trim(category)和selectOption作为参数，同时发送到后端，匹配类型与搜索条件同时满足的数据。情况一：当用户没有搜索时，selectOption为false，只需匹配类型，情况二：用户使用过搜索，搜索条件不为空时selectOption为true必须同时获取满足搜索条件和相应的类型

        if($.trim(category) == 1) {
            // classesList是不限类型的模拟数据，后台通过ajax获取，回调sh.createList方法渲染列表
            var classesList = [
                {
                    id:0,
                    classTitle:"关山高中高二美术集训",
                    addtress:"高二（4）班",
                    teacher:"魏坤",
                    time:"2018/12/07 18:00",
                    classStatus:1, // 1为正在直播，2为即将开始，3为已结束
                    imageUrl:"images/bac/class_img.png",
                    spaceNum:"3500000",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade:"高二",
                    classCategory:"美术"
                },
                {
                    id:1,
                    classTitle:"光谷高中高三物理集训",
                    addtress:"高三（4）班",
                    teacher:"李白",
                    time:"2018/11/07 15:00",
                    classStatus:2,
                    imageUrl:"images/bac/class_img.png",
                    spaceNum:"3500001",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade:"高三",
                    classCategory:"物理"
                },
                {
                    id:2,
                    classTitle:"武汉小学一年级数学集训",
                    addtress:"一年级（2）班",
                    teacher:"杜甫",
                    time:"2018/12/25 17:00",
                    classStatus:3,
                    imageUrl:"",
                    spaceNum:"3500002",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade:"一年级",
                    classCategory:"数学"
                },
                {
                    id:3,
                    classTitle:"武汉小学三年级语文集训",
                    addtress:"三年级（2）班",
                    teacher:"辛弃疾",
                    time:"2018/10/25 2:30",
                    classStatus:1,
                    imageUrl:"images/bac/class_img.png",
                    spaceNum:"3500003",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade:"三年级",
                    classCategory:"语文"
                },
                {
                    id:4,
                    classTitle:"武汉小学五年级英语集训",
                    addtress:"五年级（2）班",
                    teacher:"王之涣",
                    time:"2018/10/31 3:30",
                    classStatus:2,
                    imageUrl:"images/bac/class_img.png",
                    spaceNum:"3500004",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade:"五年级",
                    classCategory:"英语"
                },
                {
                    id:5,
                    classTitle:"关山高中高二美术集训",
                    addtress:"高二（4）班",
                    teacher:"魏坤",
                    time:"2018/12/07 18:00",
                    classStatus:3,
                    imageUrl:"",
                    spaceNum:"3500000",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade:"高二",
                    classCategory:"美术"
                },
                {
                    id:6,
                    classTitle:"光谷高中高三物理集训",
                    addtress:"高三（4）班",
                    teacher:"李白",
                    time:"2018/11/07 15:00",
                    classStatus:1,
                    imageUrl:"images/bac/class_img.png",
                    spaceNum:"3500001",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade:"高三",
                    classCategory:"物理"
                },
                {
                    id:7,
                    classTitle:"武汉小学一年级数学集训",
                    addtress:"一年级（2）班",
                    teacher:"杜甫",
                    time:"2018/12/25 17:00",
                    classStatus:3,
                    imageUrl:"images/bac/class_img.png",
                    spaceNum:"3500002",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade:"一年级",
                    classCategory:"数学"
                },
                {
                    id:8,
                    classTitle:"武汉小学三年级语文集训",
                    addtress:"三年级（2）班",
                    teacher:"辛弃疾",
                    time:"2018/10/25 2:30",
                    classStatus:2,
                    imageUrl:"",
                    spaceNum:"3500003",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade:"三年级",
                    classCategory:"语文"
                },
                {
                    id:9,
                    classTitle:"武汉小学五年级英语集训",
                    addtress:"五年级（2）班",
                    teacher:"王之涣",
                    time:"2018/10/31 3:30",
                    classStatus:2,
                    imageUrl:"images/bac/class_img.png",
                    spaceNum:"3500004",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade:"五年级",
                    classCategory:"英语"
                },
                {
                    id:10,
                    classTitle:"武汉小学一年级数学集训",
                    addtress:"一年级（2）班",
                    teacher:"杜甫",
                    time:"2018/12/25 17:00",
                    classStatus:3,
                    imageUrl:"",
                    spaceNum:"3500002",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade:"一年级",
                    classCategory:"数学"
                },
                {
                    id:11,
                    classTitle:"武汉小学三年级语文集训",
                    addtress:"三年级（2）班",
                    teacher:"辛弃疾",
                    time:"2018/10/25 2:30",
                    classStatus:1,
                    imageUrl:"images/bac/class_img.png",
                    spaceNum:"3500003",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade:"三年级",
                    classCategory:"语文"
                }
            ];

            sh.createList(classesList,8, ".classes-list",defaultImgUrl);

        }else if($.trim(category) == 2){

            // classesList是 正在直播 类型的模拟数据，后台将category作为参数发送ajax获取对应类型的数据，回调sh.createList方法渲染列表
           var classesList = [
                {
                    id: 0,
                    classTitle: "关山高中高二美术集训",
                    addtress: "高二（4）班",
                    teacher: "魏坤",
                    time: "2018/12/07 18:00",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500000",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高二",
                    classCategory: "美术"
                },
                {
                    id: 1,
                    classTitle: "光谷高中高三物理集训",
                    addtress: "高三（4）班",
                    teacher: "李白",
                    time: "2018/11/07 15:00",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500001",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高三",
                    classCategory: "物理"
                },
                {
                    id: 2,
                    classTitle: "武汉小学一年级数学集训",
                    addtress: "一年级（2）班",
                    teacher: "杜甫",
                    time: "2018/12/25 17:00",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500002",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade: "一年级",
                    classCategory: "数学"
                },
                {
                    id: 3,
                    classTitle: "武汉小学三年级语文集训",
                    addtress: "三年级（2）班",
                    teacher: "辛弃疾",
                    time: "2018/10/25 2:30",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500003",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade: "三年级",
                    classCategory: "语文"
                },
                {
                    id: 4,
                    classTitle: "关山高中高二美术集训",
                    addtress: "高二（4）班",
                    teacher: "魏坤",
                    time: "2018/12/07 18:00",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500000",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高二",
                    classCategory: "美术"
                },
                {
                    id: 5,
                    classTitle: "光谷高中高三物理集训",
                    addtress: "高三（4）班",
                    teacher: "李白",
                    time: "2018/11/07 15:00",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500001",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高三",
                    classCategory: "物理"
                },
                {
                    id: 6,
                    classTitle: "武汉小学一年级数学集训",
                    addtress: "一年级（2）班",
                    teacher: "杜甫",
                    time: "2018/12/25 17:00",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500002",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "一年级",
                    classCategory: "数学"
                },
                {
                    id: 7,
                    classTitle: "武汉小学三年级语文集训",
                    addtress: "三年级（2）班",
                    teacher: "辛弃疾",
                    time: "2018/10/25 2:30",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500003",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "三年级",
                    classCategory: "语文"
                },
                {
                    id: 8,
                    classTitle: "关山高中高二美术集训",
                    addtress: "高二（4）班",
                    teacher: "魏坤",
                    time: "2018/12/07 18:00",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500000",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高二",
                    classCategory: "美术"
                },
                {
                    id: 9,
                    classTitle: "光谷高中高三物理集训",
                    addtress: "高三（4）班",
                    teacher: "李白",
                    time: "2018/11/07 15:00",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500001",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高三",
                    classCategory: "物理"
                },
                {
                    id: 10,
                    classTitle: "武汉小学一年级数学集训",
                    addtress: "一年级（2）班",
                    teacher: "杜甫",
                    time: "2018/12/25 17:00",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500002",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "一年级",
                    classCategory: "数学"
                },
                {
                    id: 11,
                    classTitle: "武汉小学三年级语文集训",
                    addtress: "三年级（2）班",
                    teacher: "辛弃疾",
                    time: "2018/10/25 2:30",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500003",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade: "三年级",
                    classCategory: "语文"
                },

            ];
            sh.createList(classesList,8, ".classes-list",defaultImgUrl);

        }else if($.trim(category) == 3){

            // classesList是 即将直播 类型的模拟数据，后台将category作为参数发送ajax获取对应类型的数据，回调sh.createList方法渲染列表
           var classesList = [
                {
                    id: 0,
                    classTitle: "关山高中高二美术集训",
                    addtress: "高二（4）班",
                    teacher: "魏坤",
                    time: "2018/12/07 18:00",
                    classStatus: 2,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500000",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高二",
                    classCategory: "美术"
                },
                {
                    id: 1,
                    classTitle: "光谷高中高三物理集训",
                    addtress: "高三（4）班",
                    teacher: "李白",
                    time: "2018/11/07 15:00",
                    classStatus: 2,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500001",
                    isInitedUser:false, //用户是否被邀请
                    isInitedSpace:false, //空间是否被邀请
                    grade: "高三",
                    classCategory: "物理"
                },
                {
                    id: 2,
                    classTitle: "武汉小学一年级数学集训",
                    addtress: "一年级（2）班",
                    teacher: "杜甫",
                    time: "2018/12/25 17:00",
                    classStatus: 2,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500002",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "一年级",
                    classCategory: "数学"
                }
            ];
            sh.createList(classesList,8,".classes-list",defaultImgUrl);

        }else if($.trim(category) == 4){

            // classesList是 已结束/直播回放 类型的模拟数据，后台将category作为参数发送ajax获取对应类型的数据，回调sh.createList方法渲染列表
          var  classesList = [
                {
                    id: 0,
                    classTitle: "关山高中高二美术集训",
                    addtress: "高二（4）班",
                    teacher: "魏坤",
                    time: "1小时30分钟",
                    classStatus: 3,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500000",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高二",
                    classCategory: "美术"
                },
                {
                    id: 1,
                    classTitle: "光谷高中高三物理集训",
                    addtress: "高三（4）班",
                    teacher: "李白",
                    time: "2小时30分钟",
                    classStatus: 3,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500001",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高三",
                    classCategory: "物理"
                }
            ];

            sh.createList(classesList,8, ".classes-list",defaultImgUrl);

        }else if($.trim(category) == 5){

            // classesList是 邀请我的 类型的模拟数据，后台将category作为参数发送ajax获取当前用户或当前空间被邀请的数据，回调sh.createList方法渲染列表
           var classesList = [
                {
                    id: 0,
                    classTitle: "关山高中高二美术集训",
                    addtress: "高二（4）班",
                    teacher: "魏坤",
                    time: "1小时30分钟",
                    classStatus: 1,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500000",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高二",
                    classCategory: "美术"
                },
                {
                    id: 1,
                    classTitle: "光谷高中高三物理集训",
                    addtress: "高三（4）班",
                    teacher: "李白",
                    time: "2小时30分钟",
                    classStatus: 3,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500001",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高三",
                    classCategory: "物理"
                },
                {
                    id: 2,
                    classTitle: "光谷高中高三物理集训",
                    addtress: "高三（4）班",
                    teacher: "李白",
                    time: "2小时30分钟",
                    classStatus: 2,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500001",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高三",
                    classCategory: "物理"
                },
                {
                    id: 3,
                    classTitle: "光谷高中高三物理集训",
                    addtress: "高三（4）班",
                    teacher: "李白",
                    time: "2小时30分钟",
                    classStatus: 4,
                    imageUrl: "images/bac/class_img.png",
                    spaceNum: "3500001",
                    isInitedUser:true, //用户是否被邀请
                    isInitedSpace:true, //空间是否被邀请
                    grade: "高三",
                    classCategory: "物理"
                }
            ];
            // 当数据找不到时，页面显示提示
            classesList = "";
            sh.createList(classesList,8, ".classes-list",defaultImgUrl);

        }

    })

    // 搜索功能
    $(".class-search-btn").on("click",function(){
            $(".select-list dl .searchOption").remove();
            var searchMsg = $.trim($(this).prev(".classes-search-input").val());
            if($.trim(searchMsg)!=""){
                $(".select-list dl dd").eq(0).before("<dd class='searchOption'>"+ searchMsg +"<a href=\"javascript:void(0)\" class=\"del-class\"></a></dd>");
            }
            //非空时做模糊搜索
            if($.trim(searchMsg)!=""){

                // classesList是模糊搜索后的模拟数据，后台将searchMsg作为参数通过ajax发送到后台做数据过滤，将搜索出的值回传前台，数据按时间排序，由新到旧，回调sh.createList方法渲染列表
               var classesList = [
                    {
                        id: 0,
                        classTitle: "关山高中高二美术集训",
                        addtress: "高二（4）班",
                        teacher: "魏坤",
                        time: "2018/12/07 18:00",
                        classStatus: "正在直播",
                        imageUrl: "images/bac/class_img.png",
                        spaceNum: "3500000",
                        grade: "高二",
                        classCategory: "美术"
                    },
                    {
                        id: 1,
                        classTitle: "光谷高中高三物理集训",
                        addtress: "高三（4）班",
                        teacher: "李白",
                        time: "2018/11/07 15:00",
                        classStatus: "正在直播",
                        imageUrl: "images/bac/class_img.png",
                        spaceNum: "3500001",
                        grade: "高三",
                        classCategory: "物理"
                    },
                    {
                        id: 2,
                        classTitle: "武汉小学一年级数学集训",
                        addtress: "一年级（2）班",
                        teacher: "杜甫",
                        time: "2018/12/25 17:00",
                        classStatus: "正在直播",
                        imageUrl: "images/bac/class_img.png",
                        spaceNum: "3500002",
                        grade: "一年级",
                        classCategory: "数学"
                    }
                ];
                sh.createList(classesList,8,".classes-list",defaultImgUrl);
                $(".select-list dl dd a").removeClass("active");
                $(".select-list dl dd .all-category").addClass("active");

            }
    })
    //点击搜索条件删除按钮，删除搜索条件
    $(".select-list dl").on("click",".searchOption .del-class",function () {

            // 筛选条件变为不限
            $(".select-list dl dd a").removeClass("active");
            $(".select-list dl dd .all-category").addClass("active");
            $(".classes-search-input").val("");
            // ...后台在此重新获取所有类型的所有数据并回调sh.createList渲染表格
            sh.createList(classesList,8,".classes-list",defaultImgUrl);
            $(this).parent().remove();

    })
    //点击卡片出现阴影动画
    $(".classes-list").on("click",".class-item",function () {
        $(this).addClass("active").siblings(".class-item").removeClass("active");
    })

    // 二维码显示隐藏
    $(".scan-code").on("click",function(){
        $(".show-code").toggle();
    })
})

// 翻页回调，对数据进行个性化渲染，targetUl是装载数据的容器，startIndex是第一条数据的id，endIndex是最后一条数据的id，data是获取到的数据,defaultImgUrl是默认图片
function getDataAndSortCallback(targetUl,startIndex,endIndex,data,defaultImgUrl){
    // 后台可在此通过发送startIndex、endIndex两个参数获取当前页的数据，用于服务端分页
    // ...
    var contentHtml = ""
    var indexRange = endIndex-startIndex; // 需总共请求的数据条数
    if(data){

        for (var j = startIndex; j < endIndex; j++){ // 后台请求后改为for(var j=0; j < indexRange; j++)
            var classStatus = $.trim(data[j].classStatus) == 1 ? "<img src='images/icon/gif_playing.gif' class='casting'>正在直播" :
                $.trim(data[j].classStatus) == 2 ? "即将直播" :"已结束";
            var time = ($.trim(data[j].classStatus) == 1 || $.trim(data[j].classStatus) == 2) ? data[j].time +"开始" : "时长："+data[j].time ;

            var imgUrl =  data[j].imageUrl ?  data[j].imageUrl : defaultImgUrl;
            contentHtml += '  <div class="class-item">  <a href="javascript:void(0)"><div class="class-img"><img src="' + imgUrl + '" alt=""><div class="class-space-num">'+data[j].spaceNum+'</div></div> <div class="class-info"><div class="class-title">'+data[j].classTitle+'</div><div class="row"><span class="class-addtress left">'+data[j].addtress+'</span><span class="teacher right">'+data[j].teacher+'</span></div><div class="row"><span class="class-time left">'+time+'</span> <span class="class-status right">'+classStatus+'...</span></div></div></a></div>';

        }

    }else{
        contentHtml = "<div class='no-result-tip'>没有找到相关的课程</div>"
    }

    targetUl.append(contentHtml);

}
